package com.ruoyi.web.controller.model;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MechHeatingNode;
import com.ruoyi.system.domain.MechHeatingPip;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 机理建模：供热系统
 *
 * @author guixin
 */
@Controller
@RequestMapping("/model/heating")
public class ModelHeatingController extends BaseController {

    private String prefix = "model/heating";

    @RequiresPermissions("model:heating:view")
    @GetMapping()
    public String index() {
        return prefix + "/heating";
    }

    /**
     * 数据导入
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file) throws Exception
    {

        Map<String, Object> data = new HashMap<>();
        String sheetName1 = "节点";
        String sheetName2 = "管道";

        ExcelUtil<Object> util = new ExcelUtil<>(Object.class);
        Map<String, Class> map = new HashMap<>();
        // 将每个sheet页的名和需要导入的类对应，加入map集合
        map.put(sheetName1, MechHeatingNode.class);
        map.put(sheetName2, MechHeatingPip.class);
        // 将每个sheet页转成一个个Object对象数据加入List集合
        Map<String, List<Object>> dataMap = util.importExcel(map, file.getInputStream());
        data.put("dataList1", dataMap.get(sheetName1));
        data.put("dataList2", dataMap.get(sheetName2));

        return AjaxResult.success(data);
    }
}
